# delimit ;
clear ;
set more off ;
est drop _all ;
cd "R:/personlig/fenellac/menarche_replication/build" ;

* **************************************************************************** ;
* This code does the following:
* 	Takes all datasets in IHDS Wave 2 (ICSPSR_3615, DS0001-DS0014 folders)
*	Apply the supplementary syntax do-file (if any)
* 	Save the dta file in the .\output\ folder with a name that indicates contents
*
* Paper: "Age of Marriage and Women's Political Engagement: Evidence from India"
* Authors: Fenella Carpena, Francesca Jensenius
* 
* Code by Fenella Carpena
* Last update: March 3, 2020
* **************************************************************************** ;

forvalues i = 1/14 { ;
	local i_string = string(`i', "%04.0f") ;
	
	* get the dataset ; 
	use "./input/ICPSR_36151/DS`i_string'/36151-`i_string'-Data.dta", clear ;

	* check if there is a supplementary syntax do file ;
	capture confirm file "./input/ICPSR_36151/DS`i_string'/36151-`i_string'-Supplemental_syntax.do" ; 
	
	* if there is a file, run it ;
	if _rc == 0 do "./input/ICPSR_36151/DS`i_string'/36151-`i_string'-Supplemental_syntax.do" ; 
	
	* save file with name that indicates contents ;
	* DS1: Individual data
	* DS2: Household data
	* DS3: Eligible women (HH member-level)
	* DS4: Birth history (HH member-birth-level)
	* DS5: Medical staff (medical facility-employee level)
	* DS6: Medical facilities
	* DS7: Non-resident family members (HH member-level)
	* DS8: School staff (school-employee level)
	* DS9: School facilities
	* DS10: Wage and salary (HH member-level)
	* DS11: Tracking HH member-level, this is data from the tracking sheet, i.e., for tracking Round 1 HHs)
	* DS12: Village
	* DS13: Village panchayat (village panchayat-member level): details of all members of the panchayat
	* DS14: Village respondent: listing of all those who provided information for the village questionnaire ;

	local datasetnames 
	individual 
	household 
	eligible-women 
	birth-history
	medical-staff
	medical-facilities 
	non-resident-family-members
	school-staff
	school-facilities
	wage-salary-hh-roster
	tracking
	village
	village-panchayat
	village-respondent ;
	
	local desc: word `i' of `datasetnames' ;
	local i_string_short = string(`i',"%02.0f") ;
	
	save ./temp/ihds02-DS`i_string_short'-`desc', replace ;
} ;

exit ;




	
